using UnityEngine;
using System.Collections.Generic;
using System.Linq;

public interface ISkillSelector
{
    List<Transform> SelectTarget(SkillData data, Transform skillTrans);
}

public class SectorSkillSelector : ISkillSelector
{
    public List<Transform> SelectTarget(SkillData data, Transform skillTrans)
    {
        List<CharacterStatus> targets = CharacterManager.Instance.characters;
        targets = targets.FindAll(t => (Vector3.Distance(t.transform.position, skillTrans.position) <= data.item.attackDistance) &&
                              Vector3.Angle(skillTrans.forward, t.transform.position - skillTrans.position) < data.item.attackAngle / 2f &&
                              t.gameObject != data.owner &&
                              t.health > 0);

        List<Transform> result = targets.Select(t => t.transform).ToList();

        if (data.item.rangeType == SkillRangeType.Group || result.Count == 0) return result;

        Transform min = result.GetMin(t => Vector3.Distance(t.position, skillTrans.position));
        result.Clear();
        result.Add(min);
        return result;
    }
}

public class RectangleSkillSelector : ISkillSelector
{
    public List<Transform> SelectTarget(SkillData data, Transform skillTrans)
    {
        throw new System.NotImplementedException();
    }
}